package com.gateway.springboot.starter.plugin.ratelimiter;

import com.gateway.plugin.api.GatewayPlugin;
import com.gateway.plugin.base.handler.PluginDataHandler;
import com.gateway.plugin.ratelimiter.RateLimiterPlugin;
import com.gateway.plugin.ratelimiter.executor.RedisRateLimiter;
import com.gateway.plugin.ratelimiter.handler.RateLimiterPluginDataHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: api-gateway
 * @description:
 * @author: YuKai Fan
 * @create: 2025/2/6 16:21
 **/
@Configuration
@ConditionalOnProperty(value = {"gateway.plugins.rate-limiter.enabled"}, havingValue = "true", matchIfMissing = true)
public class RateLimiterPluginConfiguration {

    /**
     * RateLimiter plugin.
     *
     * @return the gateway plugin
     */
    @Bean
    public GatewayPlugin rateLimiterPlugin() {
        return new RateLimiterPlugin(new RedisRateLimiter());
    }

    /**
     * Rate limiter plugin data handler.
     *
     * @return the plugin data handler
     */
    @Bean
    public PluginDataHandler rateLimiterPluginDataHandler() {
        return new RateLimiterPluginDataHandler();
    }
}
